package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YcOrg;
import com.ruoyi.system.service.IYcOrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 油厂组织管理Controller
 *
 * @author ruoyi
 * @date 2022-10-15
 */
@RestController
@RequestMapping("/system/org")
public class YcOrgController extends BaseController
{
    @Autowired
    private IYcOrgService ycOrgService;

    /**
     * 查询油厂组织管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:org:list')")
    @GetMapping("/list")
    public AjaxResult list(YcOrg ycOrg)
    {
        List<YcOrg> list = ycOrgService.selectYcOrgList(ycOrg);
        return AjaxResult.success(list);
    }

    /**
     * 导出油厂组织管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:org:export')")
    @Log(title = "油厂组织管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YcOrg ycOrg)
    {
        List<YcOrg> list = ycOrgService.selectYcOrgList(ycOrg);
        ExcelUtil<YcOrg> util = new ExcelUtil<YcOrg>(YcOrg.class);
        util.exportExcel(response, list, "油厂组织管理数据");
    }

    /**
     * 获取油厂组织管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:org:query')")
    @GetMapping(value = "/{orgId}")
    public AjaxResult getInfo(@PathVariable("orgId") Long orgId)
    {
        return AjaxResult.success(ycOrgService.selectYcOrgByOrgId(orgId));
    }

    /**
     * 新增油厂组织管理
     */
    @PreAuthorize("@ss.hasPermi('system:org:add')")
    @Log(title = "油厂组织管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody YcOrg ycOrg)
    {
        return toAjax(ycOrgService.insertYcOrg(ycOrg));
    }

    /**
     * 修改油厂组织管理
     */
    @PreAuthorize("@ss.hasPermi('system:org:edit')")
    @Log(title = "油厂组织管理", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody YcOrg ycOrg)
    {
        return toAjax(ycOrgService.updateYcOrg(ycOrg));
    }

    /**
     * 删除油厂组织管理
     */
    @PreAuthorize("@ss.hasPermi('system:org:remove')")
    @Log(title = "油厂组织管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orgIds}")
    public AjaxResult remove(@PathVariable Long[] orgIds)
    {
        return toAjax(ycOrgService.deleteYcOrgByOrgIds(orgIds));
    }

    /**
     * 查询所有组织下拉列表
     */
    @GetMapping("/ycorgSelect")
    public AjaxResult ycorgSelect()
    {
        return AjaxResult.success(ycOrgService.selectYcOrgAll());
    }
}
